#include <iostream>
#include <thread>
#include <chrono>
#include <functional>
#include "bind_test.hpp"

int main() {
    Bind_test test1;
    
    test1.play();
    
    return 0;
}

void foo() {
    std::this_thread::sleep_for(std::chrono::seconds(1));
}

void bar() {
    std::this_thread::sleep_for(std::chrono::seconds(1));
}

int main01() {
    std::cout << "starting first helper...\n";
    auto f = std::bind(foo);
    std::thread helper1(f);
    
    helper1.join();
    
    std::cout << "starting second helper...\n";
    std::thread helper2(bar);
    
    std::cout << "waiting for helper to finish..." << std::endl;
    
    // join()阻塞当前线程，直至 *this 所标识的线程完成其执行
    // 1.join方法的作用是阻塞主线程（挡住，无法执行join以后的语句），专注执行子线程。
    // 2.多线程多join的情况下，依次执行各线程的join方法，前头一个结束了才能执行后面一个。
    
//    helper1.join();
    helper2.join();
    
    std::cout << "done!\n";
    
    return 0;
}
